<template>
  <div class="debounce-page-container">
    <base-divide-title text="按钮防抖"></base-divide-title>
    <div class="btn-debounce-wrap">
      <el-button @click="onBtnDebounce">测试防抖</el-button>
    </div>

    <base-divide-title text="文本输入防抖"></base-divide-title>
    <div class="input-debounce-wrap">
      <el-input type="text" v-model="inputValue" placeholder="请输入内容..." @input="onInputDebounce"></el-input>
    </div>
  </div>
</template>

<script>
import { debounce } from '@/utils/function';

export default {
  data() {
    return {
      inputValue: '',
    };
  },
  methods: {
    /**
     * 按钮防抖
     */
    onBtnDebounce: debounce(() => {
      console.log('debounce => ', new Date());
    }, 500),

    /**
     * 文本防抖
     */
    onInputDebounce: debounce((val) => {
      console.log('input debounce => ', val);
    }, 1000),
  },
};
</script>

<style lang="scss">
.debounce-page-container {
  width: 100%;
  height: 100%;

  .btn-debounce-wrap,
  .input-debounce-wrap {
    padding: 20px;
  }

  .input-debounce-wrap {
    .el-input {
      width: 225px;
    }
  }
}
</style>
